package com.xinhua.erp.controller;

import com.xinhua.erp.pojo.Product;
import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("product")

public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("{id}")
    public Result findById(@PathVariable long id){

        return productService.findById(id);

    }

    @GetMapping("{page}/{size}")
    public Result findAll(@PathVariable int page,@PathVariable int size){

        return productService.findAll(page, size);

    }

    @GetMapping
    public Result findAllProduct(){
        return productService.findAllProduct();
    }

    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable long id){

        return productService.deleteById(id);

    }

    @PostMapping
    public Result save(@RequestBody Product product){

        return productService.save(product);

    }

    @PutMapping("{id}")
    public Result update(@RequestBody Product product,@PathVariable Long id){

        return productService.update(product,id);

    }

    @PostMapping("search/{page}/{size}")
    public Result Search(@RequestBody Map searchMap,@PathVariable int page,@PathVariable int size){

        return productService.Search(searchMap,page,size);

    }


}
